package cn.jbolt.ai.demo.service.impl;

import cn.jbolt.ai.app.service.AiAppService;
import cn.jbolt.ai.resource.function.anno.FunctionResource;
import cn.jbolt.ai.resource.llm.entity.AiResource;
import cn.jbolt.ai.resource.llm.service.AiResourceService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import cn.jbolt.util.ReflectiveApiCall;
import cn.jbolt.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jboltai.util.http.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FunctionCallTestService {

    @Autowired
    private AiAppService appService;
    @Autowired
    private AiResourceService aiResourceService;

    @FunctionResource(desc = "根据用户名查询相关订单")
    public Result searchOrder(String userName) {
        JSONArray list = new JSONArray();
        list.add(new JSONObject().fluentPut("sn", "2023110187654565").fluentPut("createTime", "2023/11/01").fluentPut("amount", 99.9).fluentPut("state", "支付成功"));
        list.add(new JSONObject().fluentPut("sn", "2024010184334751").fluentPut("createTime", "2024/01/01").fluentPut("amount", 199.9).fluentPut("state", "支付成功"));
        list.add(new JSONObject().fluentPut("sn", "2024110194556441").fluentPut("createTime", "2024/11/01").fluentPut("amount", 9.9).fluentPut("state", "支付失败"));
        return Result.success(list);
    }


    @FunctionResource(desc = "获取当前系统中有多少个ai应用")
    public int getAppCount() {
        return (int) appService.count();
    }

    @FunctionResource(desc = "查询当前系统中有多少个可用的AI资源")
    public int getAIResourceCount() {
        return (int) aiResourceService.count(new QueryWrapper<AiResource>()
                .eq("enable", true));
    }


    @FunctionResource(desc = "根据关键词搜一道题目")
    public Result searchQuestion(String keywords) throws Exception{
        String result = HttpUtil.get("https://api.yyy001.com/api/question?question="+keywords).send().string();
        return Result.success(result);
    }



}
